
//传递日期，返回星期
function getChineseWeekday(dateStr) {
    // 创建 Date 对象
    const date = new Date(dateStr);
    // 获取星期几，返回值是 0 - 6 的整数
    const weekdayIndex = date.getDay();
    // 定义中文星期数组
    const weekdays = ['日', '一', '二', '三', '四', '五', '六'];
    // 根据索引获取中文星期
    return weekdays[weekdayIndex];
}
//日期加n天
function addDays(dateStr, days) {
    // 1. 转换为 Date 对象
    const date = new Date(dateStr);
    // 2. 增加天数
    date.setDate(date.getDate() + days);
    // 3. 格式化日期（补零处理）
    const year = date.getFullYear();
    const month = (date.getMonth() + 1).toString().padStart(2, '0');
    const day = date.getDate().toString().padStart(2, '0');
    return `${year}-${month}-${day}`;
}

//日期比较
function compareDateIsLowCurrentDate(targetDateStr) {
    // 获取当前日期
    const currentDate = new Date();
    const currentYear = currentDate.getFullYear();
    const currentMonth = String(currentDate.getMonth() + 1).padStart(2, '0');
    const currentDay = String(currentDate.getDate()).padStart(2, '0');
    const currentDateStr = `${currentYear}-${currentMonth}-${currentDay}`;
    console.info("currentDateStrcurrentDateStr:"+currentDateStr)

    // 比较日期
    return currentDateStr >= targetDateStr;
}

// 将函数导出，以便其他文件可以引用
module.exports = {
    getChineseWeekday: getChineseWeekday,
    addDays: addDays,
    compareDateIsLowCurrentDate: compareDateIsLowCurrentDate
};